//---------------------------------------------------------------------------

#ifndef CNetH
#define CNetH
//---------------------------------------------------------------------------

#include "IdTCPClient.hpp"
#include "IdUDPClient.hpp"
#include "IdUDPServer.hpp"
#include "IdTCPServer.hpp"

typedef enum
{
  bs_disabled=0,
  bs_enabled=1
}bool_state;


class DelayActive
{
public:
  DelayActive(bool bool_state=false)
   : m_fState(0)
  {
     CreateMutex();
  }

  ~DelayActive()
  {
     DeleteMutex();
  }


  bool_state &operator=(const bool_state st)
  {
     return (*this = st);
  }

  bool operator==(const bool_state st) const
  {
     return (*this == st);
  }

  bool operator!=(const bool_state st) const
  {
     return !(*this == st);
  }

  void Enable() {m_fState = bs_enabled;}
  void Disable() {m_fState = bs_disabled;}
  bool_state IsEnabled() {return m_fState;}

private:
  bool_state m_fState;
  static HANDLE m_hMutexObj;

  void CreateMutex()
  {
     //if (!m_hMutexObj)



  }

  void DeleteMutex()
  {


    // m_hMutexObj=NULL;
  }
};


typedef struct
{
   TIdUDPServer *pServer;
   TIdUDPClient *pClient;
}UDP_Componet;

typedef struct
{
   TIdTCPServer *pServer;
   TIdTCPClient *pClient;
}TCP_Componet;

typedef struct
{
   UDP_Componet udp;
   TCP_Componet tcp;
}NetworkComponets;

class CNetworkBase
{
public:

   CNetworkBase()
   {
      fInitialized=false;

      fUDPServerOpen = false;
      fUDPClintOpen = false;
      fTCPServerOpen = false;
      fTCPClintOpen = false;

      fUDPClientPresent = false;
      fUDPServerPresent = false;
      fTCPClientPresent = false;
      fTCPServerPresent = false;

      m_pUdpBuffer=NULL;
   }
   ~CNetworkBase()
   {
      NetClose();
   }

   bool NetInit(NetworkComponets *nc);
   void NetClose();

   bool SetUDPAddr(char *szIpAddrSvr, int iPortSvr, char *szIpAddrClt, int iPortClt);
   bool OpenUDP();
   bool CloseUDP();
   BOOL SendUDPString(char *szStr);
   BOOL SendUDPData(void *pData, int iSize);
   bool OnRecieveUdp(void *pData, int iSize);
   void __fastcall IdUDPServerUDPRead(TIdUDPListenerThread *AThread, TBytes AData,
          TIdSocketHandle *ABinding);


   bool SetTCPAddr(char *szIpAddrSvr, int iPortSvr, char *szIpAddrClt, int iPortClt);
   bool OpenTCP();
   bool CloseTCP();
   BOOL SendTCPString(char *szStr);
   BOOL SendTCPData(void *pData, int iSize);

   bool Enable();
   bool Disable();


   UnicodeString GetCurrentIPHost();
   bool CheckOwnIP(UnicodeString Addr);

private:
   bool fInitialized;
   bool fPortInit;
   bool fUDPServerOpen;
   bool fUDPClintOpen;
   bool fTCPServerOpen;
   bool fTCPClintOpen;

   bool fUDPClientPresent;
   bool fUDPServerPresent;
   bool fTCPClientPresent;
   bool fTCPServerPresent;


   NetworkComponets m_nc;




   byte *m_pUdpBuffer;

  /* char m_szIpAddrSvr[25];
   char m_szIpAddrClt[25];

   int m_iPortSvr;
   int m_iPortClt;
    */
  /*
   BOOL EnableServer();
   BOOL EnableClient();
   BOOL DisableServer();
   BOOL DisableClient();

   bool SetAddrUDP_Server();
   bool SetAddrUDP_Client();

    */
   bool CloseConnections();

};



#endif
